<?php
/**
 * Created by PhpStorm.
 * User: zhangligang
 * Date: 17/4/22
 * Time: 下午2:15
 */

namespace App\Http\Models;

use Illuminate\Database\Eloquent\Model;

/**
 * 商品
 * Class Goods
 * @package App\Http\Models
 */
class Goods extends Model
{
    /**
     * table name
     * @var string
     */
    protected $table = 'app_goods';

    protected $fillable = ['*'];

    /**
     * 关联颜色
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function color()
    {
        return $this->belongsTo('App\Http\Models\Color', 'color_id');
    }

    /**
     * 关联产品
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function product()
    {
        return $this->belongsTo('App\Http\Models\Product', 'product_id');
    }

    public function title()
    {
        return $this->product()->title;
    }

}